package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.service.DamageListGoodsService;
import com.atguigu.jxc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/damageListGoods")
public class DamageListGoodsController {
    @Autowired
    private DamageListGoodsService damageListGoodsService;
    @Autowired
    private UserService userService;

    //保存报损单
    @PostMapping("/save")
    public ServiceVO save(DamageList damageList, String damageListGoodsStr, HttpSession session){
        Map<String, Object> map = userService.loadUserInfo(session);

        Boolean result=damageListGoodsService.save(damageList,damageListGoodsStr,map);

        if(result){
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        }
        return new ServiceVO(ErrorCode.REQ_ERROR_CODE,ErrorCode.REQ_ERROR_MESS);
    }


    //报损单查询
    @PostMapping("/list")
    public Map<String,Object> list(String  sTime, String  eTime){
        return damageListGoodsService.list(sTime,eTime);

    }

    //查询报损单商品信息
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer damageListId){
        return damageListGoodsService.goodList(damageListId);

    }


}
